import Toast from '@vant/weapp/dist/toast/toast';

import { createImage, imgAiImage, imgAiBackground, imgAiBackgroundV2, imgOutPainting, getImageByTaskId, imgByteedit } from '@/api/painting'

import { usePaintingStore, useUserStore } from '@/store';

const paintingStore = usePaintingStore()





// 开始创建任务
export default function startCreateTask(modelTypeId) {
    return new Promise(async (resolve, reject) => {
        switch (modelTypeId) {

            case 1: // 文生图
                resolve(await createImageFn())
                break;
            case 5: // 图生图
                resolve(await imgAiImageFn())
                break;
            case 6: // 生成背景
                resolve(await imgAiBackgroundFn())
                break;
            case 7: // 高级生成背景
                resolve(await imgAiBackgroundV2Fn())
                break;
            case 8: // 扩图
                resolve(await imgOutPaintingFn())
                break;
            case 11: // 指令改图
                resolve(await imgByteeditFn())
                break;
            case 30: // 侧脸背景
                resolve(await imgAiFaceBackgroundFn())
                break;
            default:
                break;
        }
    })
}



// 文生图
function createImageFn() {
    return new Promise(async (resolve, reject) => {
        try {
            const res = await createImage(paintingStore.textCreateImage)
            resolve(res.data.taskId)
        } catch (error) {
            reject(error)
        }
    })
}


// 图生图
function imgAiImageFn() {
    return new Promise(async (resolve, reject) => {
        try {
            const res = await imgAiImage(paintingStore.pictureCreateImageObj)
            resolve(res.data.taskId)
        } catch (error) {
            reject(error)
        }
    })
}



// 生成背景图
function imgAiBackgroundFn() {
    return new Promise(async (resolve, reject) => {
        try {
            const res = await imgAiBackground(paintingStore.generationBgc)
            resolve(res.data.taskId)
        } catch (error) {
            reject(error)
        }
    })
}


// 背景图V2-高级生成背景
function imgAiBackgroundV2Fn() {
    return new Promise(async (resolve, reject) => {
        try {
            const res = await imgAiBackgroundV2(paintingStore.generationBgcV2)
            resolve(res.data.taskId)
        } catch (error) {
            reject(error)
        }
    })
}


// 背景图VIP-背景绘制
function imgAiBackgroundVIPFn() {
    return new Promise(async (resolve, reject) => {
        try {
            const res = await imgAiBackground(paintingStore.vipGenerationBgc)
            resolve(res.data.taskId)
        } catch (error) {
            reject(error)
        }
    })
}

// 指令改图
function imgByteeditFn() {
    return new Promise(async (resolve, reject) => {
        try {
            const res = await imgByteedit(paintingStore.instructDraw)
            resolve(res.data.taskId)
        } catch (error) {
            reject(error)
        }
    })
}


// 扩图
function imgOutPaintingFn() {
    return new Promise(async (resolve, reject) => {
        try {
            const res = await imgOutPainting(paintingStore.expansionPicture)
            resolve(res.data.taskId)
        } catch (error) {
            reject(error)
        }
    })
}


// 侧脸背景
function imgAiFaceBackgroundFn() {
    return new Promise(async (resolve, reject) => {
        try {
            const res = await imgAiBackground(paintingStore.faceBackground)
            resolve(res.data.taskId)
        } catch (error) {
            reject(error)
        }
    })
}





